package com.itheima.io.字符流;

import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.HashMap;
import java.util.Scanner;

import static com.itheima.io.字符流.CharDtreamDemo4_2.getMsg;

public class CharDtreamDemo4 {
    public static void main(String[] args) throws IOException {
        //获取当前已经存在的用户集合
        HashMap<String,String> hm = new HashMap<>();
        //创建输入流对象
        FileReader fr = new FileReader("day12_IO流_字符流\\a.txt");
        getMsg(fr, hm);

        //获取用户输入
        //创建键盘录入对象
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入用户名:");
        String username = sc.nextLine();
        System.out.println("请输入密码:");
        String password = sc.nextLine();

        //判断用户名是否重复
        if (username != null&& hm.containsKey(username)){
            System.out.println("用户名重复");
        }else {
            if (password != null){
                hm.put(username,password);
                fleWriter(username,password);
                System.out.println("注册成功");
            }
        }


    }

    private static void fleWriter(String username, String password) throws IOException {
        FileWriter fw = new FileWriter("day12_IO流_字符流\\a.txt" , true);
        fw.write(username + "="+password);
        fw.write(System.lineSeparator());
        fw.close();
    }
}
